﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

/// <summary>
/// Summary description for Logger
/// </summary>
public class Logger
{
    private string logFilePath;
    private static Logger instance;

	private Logger()
	{
        this.logFilePath = DataManager.BaseFilePath + "log.txt";
        if (File.Exists(this.logFilePath))
        {
            File.Delete(logFilePath);
        }
        File.CreateText(this.logFilePath).Close();
	}

    static public Logger GetLogger()
    {
        if (instance == null)
        {
            instance = new Logger();
        }
        return instance;
    }

    public void Write(string log)
    {
        object o = new object();
        lock (o)
        {
            try
            {
                StreamWriter writer = File.AppendText(this.logFilePath);
                writer.WriteLine(log);
                writer.Flush();
                writer.Close();
            }
            catch
            {
            }
        }
    }
}